<?php

/**
 * Static class for custom html.
 * @author Patrick
 *
 */

class JHTML {
	const VALUE_YES = 1;
	const VALUE_NO = 0;
	const VALUE_MALE = 1;
	const VALUE_FEMALE = 0;

	/**
	 * Yes or no for selection
	 * @return array
	 */
	public static function getBooleanValues() {
		return array(
			self::VALUE_NO => '否',
			self::VALUE_YES => '是',
		);
	}

	public static function getGenders() {
		return array(
			self::VALUE_FEMALE => '女',
			self::VALUE_MALE => '男',
		);
	}

	public static function getGender($code) {
		$genders = self::getGenders();
		return isset($genders[$code]) ? $genders[$code] : null;
	}

	public static function value($model, $attribute, $format = null) {
		$value = CHtml::value($model, $attribute);
		if ($value === null || $value === '') {
			return '<span class="value-null">未填写</span>';
		}
		if ($format !== null) {
			return Yii::app()->format->format($value, $format);
		}
		return nl2br($value);
	}

	public static function jsonHeader() {
		header('Cache-Control: no-cache, must-revalidate');
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header('Content-type: application/json');
	}
}
